package com.example.myapplication.util;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.example.myapplication.db.DBHelper;

public class UserRegistrationUtil {

    public static boolean registerNewUser(Context context, String username, String password) {
        DBHelper dbHelper = new DBHelper(context);
        SQLiteDatabase db = dbHelper.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put("username", username);
        values.put("password", password);

        // 尝试插入数据，如果插入成功则返回id，否则返回-1
        long newRowId = db.insert("users", null, values);

        // 关闭数据库连接
        db.close();

        // 如果newRowId == -1，插入失败
        return newRowId != -1;
    }
}